<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>面试题</title>
    <script>
        function test(){
            console.log(a);//undefind
            console.log(foo());//2
            var a = 1;
            function foo(){
              alert(a);//undefind
                return 2;
            }
            foo()
        }
        test()
    </script>
</head>
<body>

</body>
</html>